# | 0 | In this demonstration you'll learn how
|
---|
1 | 3 | to create menus and commands with the |
2 | 5 | Visual Basic Menu Editor and process them |
3 | 8 | with program code. The program I will |
4 | 11 | create will be a simple tool that uses the |
5 | 13 | time and date commands on a clock menu |
6 | 16 | to display the current date and time |
7 | 18 | recorded in the Windows control panel. To |
8 | 21 | build the program I'll create a label |
9 | 23 | object on my form and customize it with |
10 | 26 | property settings. First change I'll make |
11 | 29 | will be to set the alignment property to |
12 | 31 | center. Then I'll scroll down and change |
13 | 37 | the border style property to fixed |
14 | 39 | single to give it a three dimensional look. |
15 | 43 | Then I'll go down and select the font |
16 | 45 | property to make the type bigger. And in |
17 | 49 | the font dialog box I'll select bold and |
18 | 52 | 14 point. Next | I'll create a clock menu |
19 | 57 | with two commands by using the Menu |
20 | 59 | Editor utility. When you're ready to use the |
21 | 62 | Menu Editor click the form so that the |
22 | 65 | form will be selected and the Menu |
23 | 67 | Editor icon on the tool bar will be enabled. |
24 | 71 | The Menu Editor is an easy to use tool |
25 | 73 | designed to create and edit menus from |
26 | 75 | within the Visual Basic programming |
27 | 76 | environment. It contains a number of |
28 | 78 | textbuttons and buttons designed to accomplish |
29 | 81 | this task. We'll start by creating a clock |
30 | 86 | menu on our Visual Basic form. To do |
31 | 89 | that I'll create &&Clock in the caption |
32 | 95 | textbox. And I'll give that the name mnu |
33 | 99 | Clock in my program code. The && symbol |
34 | 107 | creates an access key for our clock and |
35 | 109 | this means you can press AltC to open the |
36 | 111 | menu. Mnu Clock in the name textbox is the |
37 | 119 | variable name that I'm assigning this |
38 | 120 | menu item to in my program code. And mnu |
39 | 123 | simply means menu. That's a convention |
40 | 127 | that many Visual Basic programmers |
41 | 128 | follow. Now to create the next menu item I'll |
42 | 132 | click the next button and I'll type |
43 | 138 | &&Time to create a time command. And I'll |
44 | 142 | assign that mnu Time item as a name in my |
45 | 150 | program code. And I want to click the |
46 | 154 | right button to indent that one since it's |
47 | 157 | a command on a menu. And I'll click the |
48 | 161 | next button to go to the next command. |
49 | 163 | And I'll type &&Date and the name textbox |
50 | 168 | mnu Date item for the program code. And |
51 | 175 | that completes my menu with three items | |
52 | 177 | so I'll click OK. Now that I've added |
53 | 180 | my three items a form appears in Visual |
54 | 184 | Basic with a clock menu. And when I click |
55 | 187 | that the time and date commands appear. |
56 | 191 | The C in the clock menu has been underlined |
57 | 193 | because it's an access key. The same |
58 | 194 | with the T in Time and the D in Date. And |
59 | 198 | when I'm ready to create the program |
60 | 200 | code for these items I simply click the |
61 | 201 | item in the menu when I'm in design mode. |
62 | 205 | I'll start with the time command by |
63 | 206 | clicking Time | which opens the code window. |
64 | 212 | And I'll resize the code window out just |
65 | 213 | a little bit to get a little more room. |
66 | 218 | And then I'll type label1.caption | and I |
67 | 225 | need my 1 or it would be an error | |
68 | 227 | label1.caption = Time. And I'll go on to the |
69 | 234 | next item by selecting the Date item in |
70 | 238 | the object drop down listbox. And I'll |
71 | 242 | type label1.caption = Date. And when the |
72 | 250 | program runs and this selected the |
73 | 253 | program statement will copy the date from |
74 | 255 | the system clock to the label object. The |
75 | 258 | same is true in the first program |
76 | 259 | statement I typed. Using the Time statement | |
77 | 263 | Visual Basic will copy the current time |
78 | 265 | from the system clock to the caption |
79 | 267 | property of the label object. Now I'll close |
80 | 270 | the code window and run my program. I'll |
81 | 273 | click the start button on the tool bar. |
82 | 276 | And when my program appears I'll click |
83 | 279 | the clock menu to display time and date |
84 | 281 | commands. I could also display that by |
85 | 283 | pressing AltC. And when I click the time |
86 | 287 | command I see that it's 5:55pm in the |
87 | 290 | afternoon. And when I click the date |
88 | 292 | command I see that it's 2/16/98 | February |
89 | 296 | 16th. Well as you can see | the Menu Editor |
90 | 300 | makes it quite easy to build your own |
91 | 301 | menus and associate them with program |
92 | 304 | code. |
93 | 306 | END
|